rm(list=ls())
library(tidyverse)

# Finbra 1997 does not have IBGE municipal codes. It uses UG, which is based on SIAFI.
# We use the constitutional grants database, which have both codes, to create the correspondence table.

# Read constitutional grant and create correspondence
constitutional_grants <- read_rds(here::here("data","processed","fiscalpolicy","panel_consitutional_grants.rds"))

correspondence_ibge_siafi_ug <- constitutional_grants %>% 
  distinct(mun_name,mun_code_ibge,mun_code_siafi) %>% 
  mutate(mun_ug = 980000+mun_code_siafi)

# Save

write_rds(correspondence_ibge_siafi_ug, here::here("data","processed","fiscalpolicy","correspondence_ibge_siafi_ug.rds"))
